{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\vgonz\Dropbox\Pitt\OneDrive for Business\Dissertation - Vale\Paper 2 - Political-Economic Polarization\Replication\Log\4_2_Figures_Appendix_ESS.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}29 Aug 2024, 15:44:38

{com}. do "C:\Users\vgonz\Dropbox\Pitt\OneDrive for Business\Dissertation - Vale\Paper 2 - Political-Economic Polarization\Replication\Do\4_2_Figures_Appendix_ESS.do"
{txt}
{com}. *****************************************************************************
. *                                 Figures Descriptives with ESS                                 *
. *                                                                                                                                                       *                       
. * Author:                       Valentina Gonzalez Rostani                                                      *
. * Contact:                      mag384@pitt.edu                                                                 *
. * Date:                         August 9 2024                                                                                   *
. * Version:                      Stata 17                                                                                                *                                                                          
. *                                                                                                                                                       *
. *****************************************************************************
. /*
> This do-file:
> - Creates Figure A2 using data from the ESS. 
> 
> Input:
> - Data\Appendix_ESS.dta
> 
> Output:
> - Figure A2: Share routine and non-routine 2002-2018 [Figure\Share routine and non routine.pdf]
> 
> */
. 
. *Defining Directory
. cd "C:\Users\vgonz\Dropbox\Pitt\OneDrive for Business\Dissertation - Vale\Paper 2 - Political-Economic Polarization\Replication"
{res}C:\Users\vgonz\Dropbox\Pitt\OneDrive for Business\Dissertation - Vale\Paper 2 - Political-Economic Polarization\Replication
{txt}
{com}. 
. *Calling the data
. use "Data\Appendix_ESS.dta", clear 
{txt}
{com}. 
. *******************************************************************************
. * Graphs
. *******************************************************************************
. * Graph style
. {c -(}
. grstyle clear
. set scheme s2color
. grstyle init
{res}{com}. grstyle set plain, box
. grstyle color background white
. grstyle color major_grid gs8
. grstyle linepattern major_grid dot
. {c )-}
{txt}
{com}. // Figure A2: Share routine and non-routine 2002-2018
. {c -(}
. preserve
. // Preserve the current dataset in memory to allow restoration later
. 
. // Generate a binary variable 'tokeep' to identify the countries to be kept for Figure A2
. gen tokeep = (cou == "BEL" | cou == "CZE" | cou == "EST" | cou == "HUN" | cou == "LUX" | cou == "SVK" | cou == "SVN" | cou == "DNK" | cou == "FIN" | cou == "FRA" | cou == "DEU" | cou == "GRC" | cou == "IRL" | cou == "NLD" | cou == "PRT" | cou == "ESP" | cou == "SWE" | cou == "GBR" | cou == "NOR" | cou == "CHE" | cou == "AUT" | cou == "ITA" | cou == "POL")
. 
. // Keep only the observations for the countries specified in 'tokeep'
. keep if tokeep == 1
{txt}(85,256 observations deleted)
{com}. 
. 
. // Keep observations where 'mnactic' is 1 or 3 (paid work or unemployed looking for a job), and 'rti' is not missing
. keep if inlist(mnactic, 1, 3) & rti ~= .
{txt}(181,328 observations deleted)
{com}. 
. // Generate a binary variable 'routine' to indicate whether the task is routine (rti > 0)
. gen routine = 1 if rti > 0
{txt}(99,690 missing values generated)
{com}. replace routine = 0 if rti < 0
{txt}(99,690 real changes made)
{com}. 
. // Calculate the total number of people in each occupation per year for each country and routine category
. bysort year routine cou: egen empl = sum(dweight)
. 
. // Calculate the total number of people in each ISCO2 category per year for each country
. bysort year cou: egen tot = sum(dweight)
. 
. // Calculate the share of people within each type of task (routine or non-routine) per year
. gen share = empl / tot * 100
. 
. // Label the variables with descriptive names
. label var empl "total no people within occup/year"
. label var tot "total no people with isco2 within year"
. label var share "share of people within type of task routinary or not /year"
. lab var cou "Country"
. 
. // Collapse the dataset to calculate the weighted share of routine and non-routine tasks by year and country
. collapse share [aw=pweight], by(routine year cou)
{res}{com}. 
. // Sort the dataset by country, year, and routine status
. sort cou year routine share
. 
. // Generate separate variables for the share of non-routine and routine tasks
. gen routine0 = share if routine == 0
{txt}(177 missing values generated)
{com}. gen routine1 = share if routine == 1
{txt}(177 missing values generated)
{com}. 
. // Calculate the total share of non-routine tasks per year and country
. bysort year cou: egen share0 = total(routine0)
. 
. // Calculate the total share of routine tasks per year and country
. bysort year cou: egen share1 = total(routine1)
. 
. // Calculate the polarization between non-routine and routine tasks
. gen polarization = share0 - share1
. 
. // Generate a line graph showing the share of routine and non-routine tasks over time for each country
. graph twoway ///
>     line share year if routine == 1, lc(red) legend(label(1 "Routine")) by(cou) || ///
>     line share year if routine == 0, lc(blue) legend(label(2 "Non-Routine")) by(cou)
{res}{com}. 
. // Export the graph to a PDF file
. graph export "Figure\Share routine and non routine.pdf", as(pdf) replace
{txt}{p 0 4 2}
file {bf}
Figure\Share routine and non routine.pdf{rm}
saved as
PDF
format
{p_end}
{com}. 
. // Restore the original dataset that was in memory before any modifications
. restore
.         
. {c )-}
{txt}
{com}. 
{txt}end of do-file

{com}. exit, clear
